package com.interview.spring.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author: zsg
 * @description:
 * @date: 2019/11/30 21:20
 * @modified:
 */
public class TestProxy implements InvocationHandler {

    private Object target;

    public TestProxy(Object target) {
        this.target = target;
    }

    public <T> T getProxy(){
        return (T)  Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("代理进来了");
        return method.invoke(target,args);
    }
}
